package com.hibernate.dao;

import com.hibernate.entities.tb_users;
import org.hibernate.Query;
import org.hibernate.Session;

import java.util.List;

/**
 * Created by francis on 2016/12/4.
 */
public class UserDao extends BaseDao {
    //待验证
//    public int count1() {
//        String hql = "select count(*) from tb_users as user";
//        Integer count = (Integer) getHibernateTemplate().find(hql).listIterator().next();
//        return count.intValue();
//    }
    //待验证
//    public int count2() {
//        String hql = "select count(*) from tb_users as user";
//        return ((Integer) getHibernateTemplate().iterate(hql).next()).intValue();
//    }

    public int count3() {
        Session session = HibernateSessionFactory.getSession();

        String hql = "select count(*) from tb_users as user";
        Query query = session.createQuery(hql);
        return ((Number) query.uniqueResult()).intValue();
    }
     public List<tb_users> getByIds(List<Long> ids){
        if (ids==null || ids.isEmpty()) {
            return null;
        }
        String lsql = "from tb_users where id in (:ids)";
        Query query = HibernateSessionFactory.getSession().createQuery(lsql);
        query.setParameterList("ids", ids);
        return query.list();
    }
}
